﻿package  scripts.twitterPage{
	
	import flash.display.MovieClip;
	import scripts.ClickableText;
	import scripts.XMLLoader;
	import flash.events.MouseEvent;
	import flash.events.Event;
	
	
	public class twAcBtn extends MovieClip {
		private var _bg:MovieClip;
		private var _label:ClickableText;
		public  var _link:String;
		private var _xmlloader:XMLLoader;
		public var _twXML:XML; 
		public function twAcBtn(obj:Array,objHeight:Number=0) { 
			_link=obj[1];
			addChild(createBG());
			addChild(createLabel(obj[0],objHeight));
			_bg.height = _label.height;
			_bg.width = _label.width;
			_label.addEventListener(MouseEvent.ROLL_OVER,mouseOver_handler);
			_label.addEventListener(MouseEvent.CLICK,mouseClick_handler);
		}
		private function createBG():MovieClip{
			_bg=new bluebg();
			_bg.visible=false;
			return _bg;
		}
		private function createLabel(label_name:String,objHeight:Number=0):ClickableText{
			_label = new ClickableText(label_name,true,"btn__"+label_name,580);
			_label.setBold=true;
			_label.setFontSize(20);
			_label.setColour(0x666666);
			if(objHeight!=0)
				_label.setHeight(objHeight);
			return _label;
		}
		private function mouseOver_handler(e:MouseEvent):void{
			_label.setColour(0xFFFFFF);
			_bg.visible=true;
			_label.addEventListener(MouseEvent.ROLL_OUT,mouseOut_handler);
		}
		private function mouseOut_handler(e:MouseEvent):void{
			_bg.visible=false;
			_label.setColour(0x666666);
			_label.removeEventListener(MouseEvent.ROLL_OUT,mouseOut_handler);
		}
		private function mouseClick_handler(e:MouseEvent):void{
			_xmlloader=new XMLLoader(_link);
			_xmlloader.addEventListener(Event.COMPLETE,xmlCompleteHandler);
		}
		private function xmlCompleteHandler(e:Event):void{
			_twXML=_xmlloader.getXML();
			_xmlloader.removeEventListener(Event.COMPLETE,xmlCompleteHandler);
			this.dispatchEvent(new Event("UPDATETWCONTENT"));
		}
	}
	
}
